home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2993 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: c
  5. Date: Thu, 25 Jan 1996 13:50:12 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <31076E74.128A@cmt.lpr.mail.carel.fi>
  8. References: <4e7lmg$ghh@chaos.kulnet.kuleuven.ac.be>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. Andreas De Troy wrote:
  16. > [original question snipped]
  17. >
  18. > The problem could be that your editor adds an "end-of-file"-marker at the
  19. > end of its file (ASCII-code 26 or 27 [Ctrl-Z], I don't know). The
  20. > fprintf()-function adds its characters AFTER this eof-marker.
  21. > When you load the file in your editor, it stops reading input when it
  22. > encounters this eof-marker, so it will not let you see what comes after
  23. > it. A binary dump should reveal, however, that the appended words are
  24. > really there.
  25. > Solutions:
  26. > 1. try another editor; some do *not* append this eof-mark
  27. > 2. keep your ASCII-file clean", i.e. do not save it with your editor. The
  28. > Borland-functions will not append eof-marks, so as long as your file is
  29. > exclusively produced by these functions, everything should work fine.
  30.  
  31. Or, 3. Try:
  32.  
  33.     FILE    *fp = fopen(filename, "r");
  34.     FILE    *out = fopen("temp.txt", "w");
  35.     char    buf[long_enough];
  36.  
  37.     while (fgets(buf, sizeof(buf), fp))
  38.         fprintf(out, "%s", buf);
  39.     fprintf(out, "New line of text\n");
  40.     fclose(fp);
  41.     fclose(out);
  42.     remove(filename);
  43.     rename("temp.txt", filename);
  44.  
  45. Later,
  46. AriL
  47.  
  48. -- 
  49. All my opinions are mine and mine alone.
  50.